package com.hqj.util;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HightChartUtil {

    public  static String  createBasePie(String text,List<Map<String,Object>> data){
        StringBuffer sb = new StringBuffer();
        chart c = new chart(null,null,false,"pie");
        sb.append("{");
            sb.append("\"chart\": "+ JSON.toJSONString(c)+",");
            sb.append("\"title\": {\"text\": \""+text+"\"},");
            sb.append("\"tooltip\": {\"pointFormat\": \"{series.name}: <b>{point.percentage:.2f}%</b>\"},");
            sb.append("\"plotOptions\": {\"pie\": {\"allowPointSelect\": true,\"cursor\": \"pointer\",\"dataLabels\": {\"enabled\": true,\"format\": \"<b>{point.name}</b>: {point.percentage:.1f} %\"}}},");
            sb.append("\"series\": [{\"name\": \"占比\",\"colorByPoint\": true,\"data\": "+JSON.toJSONString(data)+"}]");

        sb.append("}");
        return sb.toString();
    }

    public static String createLineBarColumn(String  text,String subText,String yAxis,String suffix,List<String> categories,List<Map<String,Object>> list){
        StringBuffer sb = new StringBuffer();
        sb.append("{");
            sb.append("\"chart\":{\"type\":\"column\"},");
            sb.append("\"title\": {\"text\": \""+text+"\",\"x\": -20},");
            sb.append("\"subtitle\": {\"text\": \""+subText+"\",\"x\": -20},");
            sb.append("\"xAxis\": {\"categories\": "+JSON.toJSONString(categories)+"},");
            sb.append("\"yAxis\": {\"title\": {\"text\": \""+yAxis+"\"},\"plotLines\": [{\"value\": 0,\"width\": 1,\"color\": \"#808080\"}]},");
            sb.append("\"tooltip\": {\"valueSuffix\": \""+suffix+"\"},");
            sb.append("\"legend\": {\"layout\": \"vertical\",\"align\": \"right\",\"verticalAlign\": \"middle\",\"borderWidth\": 0},");
            sb.append("\"series\": "+JSON.toJSONString(list)+"");
        sb.append("}");
        return sb.toString();

    }

}
class chart{
    private String plotBackgroundColor;
    private String plotBorderWidth;
    private boolean plotShadow;
    private String type;

    public chart() {}

    public chart(String plotBackgroundColor, String plotBorderWidth, boolean plotShadow, String type) {
        this.plotBackgroundColor = plotBackgroundColor;
        this.plotBorderWidth = plotBorderWidth;
        this.plotShadow = plotShadow;
        this.type = type;
    }

    public String getPlotBackgroundColor() {
        return plotBackgroundColor;
    }

    public void setPlotBackgroundColor(String plotBackgroundColor) {
        this.plotBackgroundColor = plotBackgroundColor;
    }

    public String getPlotBorderWidth() {
        return plotBorderWidth;
    }

    public void setPlotBorderWidth(String plotBorderWidth) {
        this.plotBorderWidth = plotBorderWidth;
    }

    public boolean isPlotShadow() {
        return plotShadow;
    }

    public void setPlotShadow(boolean plotShadow) {
        this.plotShadow = plotShadow;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}